#!/usr/bin/python3
# -*- coding: UTF-8 -*-

from app import App
from utils.tools import Tools
from utils.element import Element
import gol
gol._init()
from os import popen as osPopen, path as osPath  # 管道处理

# 福利
btnFL = []
# 看视频赚海量金币
btnVideo = []
# 退出按钮
btnVideoClose = []

class Init(App):
    def __init__(self):
        # python2 不支持 super().__init__()
        App().__init__()
        self.ele = Element()
        self.tool = Tools()

    # 首页 -> 签到领现金按钮
    def getFL(self):
        global btnFL
        ele = self.ele
        tool = self.tool
        if len(btnFL) == 0:
            ele.init()
            aPoint = ele.findElementsByName("福利")
            if isinstance(aPoint[0], tuple):
                btnFL = aPoint[0]
            else:
                btnFL = aPoint

        tool.tap(btnFL[0], btnFL[1])
        tool.setSleep(8)

    # 商品浏览 点击逛下一个
    def getVideo(self):
        global btnVideo, btnVideoClose
        ele = self.ele
        tool = self.tool
        if len(btnVideo) == 0:
            ele.init()
            aPoint = ele.findElementsByName("看视频赚海量金币")
            print(aPoint)
            if isinstance(aPoint, tuple):
                btnVideo = aPoint
            else:
                btnVideo = aPoint[0]

        tool.setSleep(5)
        tool.tap(btnVideo[0], btnVideo[1])
        tool.setSleep(45)

        # 关闭视频
        if len(btnVideoClose) == 0:
            ele.init()
            aPoint2 = ele.findElementById("com.dragon.read:id/tt_video_ad_close")
            if isinstance(aPoint2, tuple):
                btnVideoClose = aPoint2
            else:
                btnVideoClose = aPoint2[0]
        tool.tap(btnVideoClose[0], btnVideoClose[1])

    # def whildVideo

    # 判断视频是不是已经处理完
    def isDoneVideo(self):
        ele = self.ele

        ele.init()
        aPoint = ele.findElementsByName("最高得80金币/次，已完成10/10次")
        return len(aPoint)


    def test(self):
        self.ele.init()



run = Init()
run.isDoneVideo()

